package qinggui.mlz.smsservice.service;

import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qinggui.mlz.smsservice.entity.SmsCrond;
import qinggui.mlz.smsservice.mapper.SmsCrondMapper;

import java.time.LocalDateTime;

@Service
public class SmsCrondService {
    @Autowired
    private SmsCrondMapper smsCrondMapper;
    public String cronSend(String phone) {
        // 仅将手机号存库，后续定时任务扫描表，有就发送。
        LocalDateTime now = LocalDateTime.now();
        String code = RandomStringUtils.randomNumeric(6);
        Integer cronSend = smsCrondMapper.createCronSend(new SmsCrond().setPhone(phone).setContent("【清规】验证码"+ code)
                .setStatus(Byte.valueOf("0")).setCreateTime(now).setUpdateTime(now).setIsDeleted(Byte.valueOf("0")));
        if (cronSend == 1) {
            return "success";
        }
        return "fail";
    }
}
